import java.util.*;
import library.util.*;

public class ArrayContainerTest {
	
    public static void main(String[] args) {

    	ArrayContainer   array_container = new ArrayContainer(1000);

    	class testobject implements Comparable
    	{
    	  public int id;
    	  public String str;

    	  testobject(int i, String s)
    	  {
            id = i;
            str = s;
    	  }

    	  testobject(int i)
    	  {
            this(i,"");
    	  }

    	  public String toString(){
    		  return new String(str + "[" + id + "]");
    	  }
    	  
		  public int compareTo(Object obj) {
			  testobject t1 = (testobject)obj;
			  if(t1.id < id)
				  return -1;
			  else if(t1.id > id)
				  return 1;
			  else
				  return 0;
		  }
 
    	}

    	class MyComparator implements Comparator{
   		 
    		  public int compare(Object emp1, Object emp2){
    			  testobject t1 = (testobject)emp1;
    			  testobject t2 = (testobject)emp2;
    			  if(t1.id < t2.id)
    				  return -1;
    			  else if(t1.id > t2.id)
    				  return 1;
    			  else
    				  return 0;
    		  }
    		}
    	
//        Set<Object> set = new HashSet<Object>();
//        Set set = new HashSet(); //no custom comparator   : 1.328905283
        Set set = new TreeSet(new MyComparator()); //0.385965638
//        Set set = new  LinkedHashSet(); //no custom comparator   : 0.201050693

        final int max_count = 1500;

        System.out.println("elements count: " + max_count*max_count);
        int data = 0;
        for(int icount = 0; icount < max_count; icount ++)
        {
          LinkedList ll = new LinkedList();
          for(int iccount = 0; iccount < max_count; iccount ++)
          {
            ll.add((Object)new testobject(data++));
          }
          array_container.addContainer(ll);
        }
        
        List l = array_container.getContainer(0);
//        System.out.println(l.size());
        
        
        long s_cont = System.nanoTime();
        
        int max_size = array_container.size();
        for(int icount_arr = 0; icount_arr < max_size; icount_arr ++)
        {
           array_container.get(icount_arr);
        }
        long e_cont = System.nanoTime();
        System.err.println("array_container: " + max_size + ": " + (double)(e_cont-s_cont) / (double)1000000000);
       

        
        int elemet_id = (max_count*max_count)-1;
        long ls = System.nanoTime();
        testobject ielem = (testobject)array_container.get(elemet_id);
        long le = System.nanoTime();
        System.err.println("get element [" + ielem + "]: " + elemet_id + "/" + (max_count*max_count) +  " : " +((double)(le-ls) / (double)1000000000));
        
        ls = System.nanoTime();
        ielem = (testobject)array_container.getElementMatrix(elemet_id);
        le = System.nanoTime();
        System.err.println("get element matrix [" + ielem + "]: " + elemet_id + "/" + (max_count*max_count) +  ":" +((double)(le-ls) / (double)1000000000));
        

        testobject to = new testobject(555555);
        array_container.set(elemet_id, to);
        to = (testobject)array_container.getElementMatrix(elemet_id);
        to.id = 777;
        to = (testobject)array_container.getElementMatrix(elemet_id);
        System.err.println("new element value is: " + to);
        
        
        
        for(int icount = 0; icount < max_count; icount ++)
        {
          set.add(new testobject(icount, new String("str" + icount)));
        }
        
        Set set1 = new TreeSet(new MyComparator());
        for(int icount = max_count; icount < max_count; icount ++)
        {
          set1.add(new testobject(icount, new String("str" + icount)));
        }

        
        long s = System.nanoTime();
        set.addAll(set1);
        long e = System.nanoTime();
/*
        Iterator it = set.iterator();
        while(it.hasNext())
        {
          System.out.println(it.next());
        }
        */
        System.err.println("set.addAll(set1): " + (double)(e-s) / (double)1000000000);
        
        
        s = System.nanoTime();
        Object to_array[] = set.toArray();
        e = System.nanoTime();
        System.err.println("toArray: " + (double)(e-s) / (double)1000000000);
        testobject tobj = (testobject)to_array[100];
        System.err.println(tobj);
/*        
        set.add("A");
        set.add(new Long(10));
        set.add(new Date());
        //
        // Convert the Set to a List can be done by passing the Set instance into
        // the constructor of a List implementation class such as ArrayList.
        //
        List<Object> list = new ArrayList<Object>(set);
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            System.out.println("Object = " + o);
        }
*/
    }
}
